<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :show="show" @click-show="show = !show" :fixed="true" :back="true" color="#fff" title="履职管理"></uni-navbar></view>

		<view class="filter-box" v-if="show">
			<view class="form-box">
				<u-form ref="uForm">
					<u-form-item class="form-item" label="届次">
						<u-input v-model="jieci" type="select" :select-open="jcShow" placeholder="请选择届次" @click="jcShow = true" />
						<u-select v-model="jcShow" mode="mutil-column-auto" :list="jcList" @confirm="jcConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="年度"><date-time-picker placeholder="请选择年度" :defaultValue="perform.year" fields="year" :old="true" @change="yearChange"></date-time-picker></u-form-item>
				</u-form>
			</view>
			<view class="fiexd-btm">
				<view class="flex-box">
					<u-button class="form-btn" type="default" @click="resert">清除</u-button>
					<u-button class="form-btn" type="error" @click="filter">确定</u-button>
				</view>
			</view>
		</view>

		<!-- <view class="u-line"></view> -->
		<view class="tab-nav">
			<view class="tab-item" :class="tabIndex == 1 ? 'active' : ''" @click="tab(1)">本届</view>
			<view class="tab-item" :class="tabIndex == 0 ? 'active' : ''" @click="tab(0)">本年度</view>

			<view class="search-filter" @click="show = !show"><view>筛选</view></view>
		</view>
		<view class="duties-box">
			<view class="duties-inner">
				<view class="duties-info">
					<view><image class="image" :src="$imagePreview(dutiesInfo.touxiang)" mode="aspectFill"></image></view>
					<view class="info-text">
						<view class="name">{{ dutiesInfo.userName }}</view>
						<view class="tag-box" v-if="dutiesInfo">
							<text class="tag clamp">性别:{{ dutiesInfo.sex || '' }}</text>
							<text class="tag clamp">代表团:{{ dutiesInfo.wyhdzName || '' }}</text>
							<text class="tag clamp">党派:{{ dutiesInfo.dangpai || '' }}</text>
						</view>
					</view>
				</view>
				<view class="score">
					<view class="clamp">
						履职积分：
						<text class="span">{{ dutiesInfo.sumScore }}</text>
					</view>
					<view class="clamp">
						排名情况：
						<text class="span">{{ dutiesInfo.ranking }}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="duties-title">
			大 会 期 间 履 职
			<text v-if="dutiesInfo.baseSumScore">({{ dutiesInfo.baseSumScore }})</text>
		</view>
		<u-cell-group class="link-list">
			<block v-for="(item, index) of moduleList_base" :key="index"><u-cell-item :title="item.moduleName" :value="item.moduleScore + '分'" @click="navTo(item)"></u-cell-item></block>
		</u-cell-group>
		<view class="duties-title">
			代 表 主 题 活 动
			<text v-if="dutiesInfo.otherSumScore">({{ dutiesInfo.otherSumScore }})</text>
		</view>
		<u-cell-group class="link-list">
			<block v-for="(item, index) of moduleList_other" :key="index"><u-cell-item :title="item.moduleName" :value="item.moduleScore + '分'" @click="navTo(item)"></u-cell-item></block>
		</u-cell-group>
	</view>
</template>

<script>
import dateTimePicker from '@/components/uni-datetime-picker';
import { mapState } from 'vuex';
export default {
	components: {
		dateTimePicker
	},
	data() {
		return {
			show: false,
			tabIndex: 1,
			jieci: '',
			jcShow: false,
			jcList: [],
			moduleList_base: [],
			moduleList_other: [],

			dutiesInfo: {},
			perform: {
				year: '',
				ciId: '',
				jieId: '',
				yearOrJie: 'jie'
			}
		};
	},
	onLoad(option) {
		this.loadLogin();
		if (option && option.currentUserId) {
			this.userId = option.currentUserId;
		}
		this.loadData();
		this.jieciData();
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
				this.roleCodes = this.userInfo.roleCodes.join(',');
				
				this.jieci = this.userInfo.jieCi.pName + this.userInfo.jieCi.name;
				this.perform.jieId = this.userInfo.jieCi.pid;
				this.perform.ciId = this.userInfo.jieCi.id;
			} else {
				this.$logout();
			}
		},
		loadData() {
			let data = {
				userId: this.userId,
				clientCode: this.clientCode,
				roleCodes: this.roleCodes,
				...this.perform
			};
			this.$request('/perform/score/app_eval_detail', data, {
				load: true
			}).then((res) => {
				this.moduleList_base = [];
				this.moduleList_other = [];
				this.dutiesInfo = res.data;
				res.data.scoreMap.forEach((item) => {
					if (item.moduleCode.indexOf('base') != -1) {
						this.moduleList_base.push(item);
					} else {
						this.moduleList_other.push(item);
					}
				});
			});
		},
		tab(e) {
			this.tabIndex = e;
			if (e == 0) {
				this.perform.year = this.userInfo.jieCi.year;
				this.jieci = '';
				this.perform.jieId = '';
				this.perform.ciId = '';
				this.perform.yearOrJie = 'year';
			} else {
				this.perform.year = '';
				this.jieci = this.userInfo.jieCi.pName + this.userInfo.jieCi.name;
				this.perform.jieId = this.userInfo.jieCi.pid;
				this.perform.ciId = this.userInfo.jieCi.id;
				this.perform.yearOrJie = 'jie';
			}
			this.loadData('refresh');
		},
		yearChange({ date }) {
			this.perform.year = date.year.toString();
		},
		jcConfirm(e) {
			this.jieci = e[0].label + e[1].label;
			this.perform.jieId = e[0].value;
			this.perform.ciId = e[1].value;
		},
		filter() {
			this.show = false;
			this.tabIndex = 0;
			this.loadData('refresh');
		},
		resert() {
			this.show = false;
			this.perform.userName = '';
			this.jieci = this.userInfo.jieCi.pName + this.userInfo.jieCi.name;
			this.perform.jieId = this.userInfo.jieCi.pid;
			this.perform.ciId = this.userInfo.jieCi.id;
			this.tabIndex = 0;
			this.loadData('refresh');
		},
		search(e) {
			this.perform.userName = e;
			this.loadData('refresh');
		},
		jieciData() {
			let data = {
				clientCode: this.clientCode,
				jieCi: {
					pid: ''
				}
			};
			this.$request('/jie-ci/list', data).then((res) => {
				this.jcList = [];
				let jieArr = [];
				let ciArr = [];
				res.data.forEach((item) => {
					data.jieCi.pid = item.id;
					this.$request('/jie-ci/list', data).then((res) => {
						ciArr = [];
						res.data.forEach((key) => {
							ciArr.push({
								value: key.id,
								label: key.name
							});
						});
						this.jcList.push({
							value: item.id,
							label: item.name,
							children: ciArr
						});
					});
				});
			});
		},
		navTo(item) {
			console.log(item);
			if (item.moduleName == '议案') {
				uni.navigateTo({
					url: '/pagesB/propose/list_duties?currentUserId=' + this.userId + '&jieId=' + this.perform.jieId + '&ciId=' + this.perform.ciId
				});
			} else if (item.moduleName == '建议') {
				uni.navigateTo({
					url: '/pagesB/proposal/list_duties?currentUserId=' + this.userId + '&jieId=' + this.perform.jieId + '&ciId=' + this.perform.ciId
				});
			} else {
				if (!item.menuCode) {
					this.$msg('没有配置关联菜单');
					return false;
				}
				let type = '';
				switch (item.moduleName) {
					case '全委会议':
						type = '1';
						break;
					case '常委会议':
						type = '3';
						break;
					case '其他会议':
						type = '6';
						break;
					case '专委会会议':
						type = '11';
						break;
					default:
						break;
				}
				uni.navigateTo({
					url: '/pagesA/duties/list?flag=' + item.menuCode.replace('_add', '') + '&code=' + item.moduleNum + '&name=' + item.moduleName + '&currentUserId=' + this.userId + '&jieId=' + this.perform.jieId + '&ciId=' + this.perform.ciId + '&type=' + type
				});
			}
		}
	}
};
</script>

<style lang="scss">
.tab-nav {
	position: relative;
	font-size: 14px;
	color: #666;
	line-height: 60rpx;
	text-align: center;
	background-color: #fff;

	.tab-item {
		margin: 18rpx 10rpx;
		position: relative;
		width: 140rpx;
		height: 60rpx;
		color: #666;
		border-radius: 6rpx;
		background-color: #e6e7e8;
	}

	.tab-item.active {
		font-weight: bold;
		color: #fff;
		background-color: #e5231a;
	}

	.search-filter {
		position: absolute;
		right: 30rpx;
		top: 18rpx;
		width: 120rpx;
		height: 60rpx;
		border-radius: 6rpx;
		background-color: #e6e7e8;
	}
}

.filter-box {
	position: fixed;
	left: 0;
	top: 0;
	bottom: 0;
	right: 0;
	z-index: 998;
	background-color: #fff;
}

.duties-box {
	padding: 40rpx;
	background-color: #fff;

	.score {
		display: flex;
		justify-content: space-between;
		font-size: 15px;
		font-weight: bold;
		color: #666;
		line-height: 42rpx;

		.clamp {
			max-width: 48%;
		}

		.span {
			color: #e5231a;
		}
	}

	.duties-info {
		display: flex;
		align-items: center;
		margin-bottom: 46rpx;
		min-height: 120rpx;

		.name {
			min-height: 56rpx;
			font-size: 20px;
			font-weight: bold;
			line-height: 56rpx;
		}

		.tag-box {
			margin-top: 10rpx;
			display: flex;
		}

		.tag {
			margin-right: 14rpx;
			max-width: 240rpx;
			min-width: 120rpx;
			padding: 0 20rpx;
			height: 44rpx;
			font-size: 11px;
			color: #fff;
			line-height: 44rpx;
			text-align: center;
			background: #e5231a;
			border-radius: 22rpx;
		}

		.image {
			display: block;
			margin-right: 26rpx;
			width: 120rpx;
			height: 120rpx;
			border-radius: 120rpx;
		}
	}
}

.duties-title {
	position: relative;
	margin: 0 30rpx;
	padding-left: 30rpx;
	font-size: 15px;
	color: #333;
	font-weight: bold;
	line-height: 80rpx;

	&::before {
		position: absolute;
		left: 6rpx;
		top: 50%;
		margin-top: -16rpx;
		width: 6rpx;
		height: 30rpx;
		content: '';
		background-color: #e5231a;
	}
}

.link-list {
	display: block;
	background-color: #fff;
}

.form-box {
	.form-item {
		@include mp-flex;
	}
}

.fiexd-btm {
	position: static;
	padding: 30rpx;
}
</style>
